package cn.myzqu.sign.message.server.util;

import io.jsonwebtoken.Claims;
import lombok.extern.slf4j.Slf4j;

import javax.servlet.http.HttpServletRequest;

/**
 * token常用操作工具类
 * @Author: 的川
 * @Date: 2019/1/17.
 */
@Slf4j
public class TokenUtil {

    /**  加密算法 */
    public final static String hashAlgorithmName = "SHA-256";
    /**  循环次数 */
    public final static int hashIterations = 16;

    public static Integer getUserId(HttpServletRequest request) throws Exception{
        String accessToken = request.getHeader("accessToken");
        log.info("accessToken:"+accessToken);
        if(accessToken!=null){
            Claims claims = JWTUtil.validateJWT(accessToken);
            log.info(claims.toString());
            if(claims != null){
                return Integer.parseInt(claims.getId());
            }
        }
        return 0;
    }
}
